#from threading import *
import threading

RLock = threading.RLock


def BoundedSemaphore( value=1 ):
  sem = threading.BoundedSemaphore( value=value )
  sem.locked = lambda : sem._initial_value == sem._Semaphore__value
  return sem

'''
class BoundedSemaphore(object):
  def __init__(self, value=1):
    self._value = value
    self._sem = sem = threading.BoundedSemaphore( value=value )
    self.acquire = sem.acquire
    self.release = sem.release
    self.__enter__ = sem.__enter__
    self.__exit__ = sem.__exit__

  def locked(self):
    return self._value == self._sem._Semaphore__value

'''